<template>
    <Modal v-model="modal.show" width="180" :title="modal.title" @on-ok="ok" @on-cancel="cancel">
        <Input v-model="modal.roleName" placeholder="角色名称" style="width: 150px" />
    </Modal>
</template>
<script setup>
import { reactive } from "vue";
import http from '@/util/http'
let { proxy } = getCurrentInstance();
const emit = defineEmits(['initRole'])
const modal = reactive({ show: false, title: "", roleName: "", roleID: "" });
const show = (roleID) => {
    modal.show = true;
    if (roleID === '') {
        modal.title = "添加角色"
    } else {
        modal.title = "编辑角色"
        http.get("/Basic/Role/Detail?id=" + roleID, {}, (response) => {
            modal.roleID = response.data.data.roleID
            modal.roleName = response.data.data.name
        });
    }
}
const ok = () => {
    http.post("/Basic/Role/AddOrUpdate", { name: modal.roleName, roleID: modal.roleID }, (response) => {
        if (response.data.flag) {
            emit('initRole');
            proxy.$Message.success(response.data.msg);
        } else {
            proxy.$Message.error(response.data.msg);
        }
    });
}
defineExpose({
    show,
});
</script>